package com.icebartech.core.modules;

import java.util.List;

import javax.annotation.PostConstruct;

/**
 * service抽象类，封装常用的crud方法
 * @author wenhsh
 *
 */
public abstract class AbstractService implements BaseService {

	private BaseMapper baseMapper;
	
	@PostConstruct
	private void initConfig() {
		this.baseMapper = this.getBaseMapper();
	}
	
	/**
	 * 获取对应的mapper类，交给实现类来实现
	 * @return
	 */
	public abstract BaseMapper getBaseMapper();
	
	@Override
	public <Entity> int add(Entity record) {
		return baseMapper.insert(record);
	}
	
	@Override
	public <Entity> int addSelective(Entity record) {
		return baseMapper.insertSelective(record);
	}
	
	@Override
	public <Entity> int update(Entity record) {
		return baseMapper.updateByPrimaryKey(record);
	}
	
	@Override
	public <Entity> int updateSelective(Entity record) {
		return baseMapper.updateByPrimaryKeySelective(record);
	}
	
	@Override
	public int deleteById(Long id) {
		return baseMapper.deleteByPrimaryKey(id);
	}
	
	@Override
	public <Entity> Entity findById(Long id) {
		return baseMapper.selectByPrimaryKey(id);
	}
	
	@Override
	public <Entity> List<Entity> findByList(Entity record) {
		return baseMapper.selectBySelective(record);
	}
}
